package com.cloudweb.oa.controller;

import cn.js.fan.util.ErrMsgException;
import cn.js.fan.util.ParamUtil;
import cn.js.fan.util.StrUtil;
import cn.js.fan.util.XMLConfig;
import cn.js.fan.web.Global;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cloudweb.oa.entity.Group;
import com.cloudweb.oa.exception.ValidateException;
import com.cloudweb.oa.utils.ResponseUtil;
import com.cloudweb.oa.vo.Result;
import com.redmoon.oa.android.CloudConfig;
import com.redmoon.oa.flow.WorkflowConfig;
import com.redmoon.oa.kernel.License;
import com.redmoon.oa.person.UserLevelDb;
import com.redmoon.oa.person.UserLevelMgr;
import com.redmoon.oa.ui.Skin;
import com.redmoon.oa.ui.SkinMgr;
import com.redmoon.oa.util.TwoDimensionCode;
import io.swagger.annotations.*;
import org.jdom.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.*;

import com.redmoon.oa.Config;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "配置管理")
@Controller
@RequestMapping("/config")
public class ConfigController {
    @Autowired
    HttpServletRequest request;

    @Autowired
    ResponseUtil responseUtil;

    @ApiOperation(value = "配置管理", notes = "配置管理", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kind", value = "类型", required = false, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @ResponseBody
    @RequestMapping(value = "/list")
    public Result<Object> list(@RequestParam(required = false) String kind) throws ValidateException {
        JSONObject jsonResult = new JSONObject();
        jsonResult.put("isUseSMS", com.redmoon.oa.sms.SMSFactory.isUseSMS());

        if (kind == null) {
            kind = "";
        }

        Config cfg = Config.getInstance();
        List<Element> elements = cfg.getDoc().getRootElement().getChild("oa").getChildren();

        JSONArray jsonAry = new JSONArray();
        for (Element e : elements) {
            String isDisplay = e.getAttributeValue("isDisplay");
            if ("false".equals(isDisplay)) {
                continue;
            }

            JSONObject json = new JSONObject();
            json.put("name", e.getName());
            json.put("value", e.getValue());
            json.put("desc", StrUtil.getNullStr(e.getAttributeValue("desc")));
            String type = StrUtil.getNullStr(e.getAttributeValue("type"));
            if ("true".equals(e.getValue()) || "false".equals(e.getValue())) {
                type = "boolean";
            }
            boolean isFlowDesigner = "flowDesignerType".equals(e.getName());

            JSONArray optAry = new JSONArray();
            String opts = e.getAttributeValue("options");
            String[] ary = StrUtil.split(opts, ",");
            if (ary != null) {
                for (String item : ary) {
                    String[] aryOpts = StrUtil.split(item, "\\|");
                    if (aryOpts != null && aryOpts.length == 2) {
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("value", aryOpts[0]);
                        jsonObject.put("name", aryOpts[1]);
                        optAry.add(jsonObject);
                    }
                }
            }
            json.put("options", optAry);
            if (optAry.size() > 0) {
                type = "select";
            }

            json.put("type", type);

            json.put("kind", StrUtil.getNullStr(e.getAttributeValue("kind")));
            jsonAry.add(json);
        }
        jsonResult.put("list", jsonAry);
        return new Result<>(jsonResult);
    }

    @ApiOperation(value = "编辑Email", notes = "编辑Email", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @ResponseBody
    @RequestMapping(value = "/editEmailPage")
    public Result<Object> editEmailPage() throws ValidateException {
        JSONObject json = new JSONObject();
        json.put("Application.smtpServer", Global.smtpServer);
        json.put("Application.smtpPort", Global.smtpPort);
        json.put("Application.smtpUser", Global.smtpUser);
        json.put("Application.smtpPwd", Global.smtpPwd);
        json.put("Application.email", Global.email);
        json.put("Application.smtpSSL", Global.smtpSSL);
        json.put("Application.smtpCharset", Global.smtpCharset);

        Config cfg = Config.getInstance();
        boolean flowNotifyByEmail = cfg.getBooleanProperty("flowNotifyByEmail");
        json.put("flowNotifyByEmail", flowNotifyByEmail);

        return new Result<>(json);
    }

    @ApiOperation(value = "保存配置", notes = "保存配置", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "参数名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "value", value = "参数值", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/updateConfig", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> updateConfig(@RequestParam String name, @RequestParam String value) {
        Config myconfig = Config.getInstance();
        myconfig.put(name, value);

        // 同步系统名称至config_sys.xml
        if ("enterprise".equals(name)) {
            TwoDimensionCode.generate2DCodeByMobileClient();
            XMLConfig cfg = new XMLConfig("config_sys.xml", false, "utf-8");
            cfg.set("Application.name", value);
            cfg.writemodify();
            Global.getInstance().init();
        }

        return new Result<>();
    }

    @ApiOperation(value = "隐藏配置", notes = "隐藏配置", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/hideElement", method = RequestMethod.POST, produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> hideElement(@RequestParam() String name) {
        Config myconfig = Config.getInstance();
        myconfig.setIsDisplay(name, false);
        return new Result<>();
    }

    @ApiOperation(value = "保存Email配置", notes = "保存Email配置", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "flowNotifyByEmail", value = "流程交办时是否发Email提醒", required = false, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/updateEmail", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> updateEmail(String flowNotifyByEmail) {
        Config cfg = Config.getInstance();
        if (flowNotifyByEmail == null || "".equals(flowNotifyByEmail)) {
            flowNotifyByEmail = "false";
        }
        cfg.put("flowNotifyByEmail", flowNotifyByEmail);
        cfg.writemodify();

        boolean isSmtpSSLFound = false;
        XMLConfig cfgSys = new XMLConfig("config_sys.xml", false, "utf-8");
        Enumeration e = request.getParameterNames();
        while (e.hasMoreElements()) {
            String fieldName = (String) e.nextElement();
            if (fieldName.startsWith("Application")) {
                String value = ParamUtil.get(request, fieldName);
                if ("Application.smtpSSL".equals(fieldName)) {
                    isSmtpSSLFound = true;
                }
                if ("Application.smtpCharset".equals(fieldName) && "other".equals(value)) {
                    value = ParamUtil.get(request, "otherCharset");
                }
                cfgSys.set(fieldName, value);
            }
        }

        if (!isSmtpSSLFound) {
            cfgSys.set("Application.smtpSSL", "false");
        }
        cfgSys.writemodify();
        Global.getInstance().init();
        return new Result<>();
    }

    @ApiOperation(value = "编辑流程按钮配置页面", notes = "编辑流程按钮配置", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/editFlowButtonPage")
    @ResponseBody
    public Result<Object> editFlowButtonConfigPage() {
        com.redmoon.oa.flow.FlowConfig flowConfig = new com.redmoon.oa.flow.FlowConfig();

        Element root = flowConfig.getRootElement();
        List<Element> elements = root.getChildren();

        JSONArray jsonAry = new JSONArray();
        for (Element e : elements) {
            String name = e.getName();
            if (!name.startsWith("FLOW_BUTTON_")) {
                continue;
            }

            JSONObject json = new JSONObject();

            json.put("name", name);
            json.put("value", e.getValue());
            json.put("title", StrUtil.getNullStr(e.getAttributeValue("title")));
            json.put("isDisplay", StrUtil.getNullStr(e.getAttributeValue("isDisplay")));

            jsonAry.add(json);
        }

        return new Result<>(jsonAry);
    }

    @ApiOperation(value = "保存流程按钮配置", notes = "保存流程按钮配置", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "value", value = "值", required = true, dataType = "String"),
            @ApiImplicitParam(name = "title", value = "提示信息", required = false, dataType = "String"),
            @ApiImplicitParam(name = "isDisplay", value = "是否启用", required = false, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/updateFlowButton", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> updateFlowButton(@RequestParam(value = "name") String name, @RequestParam(value = "value") String value, String title, String isDisplay) throws ValidateException {
        com.redmoon.oa.flow.FlowConfig flowConfig = new com.redmoon.oa.flow.FlowConfig();
        if (value == null || "".equals(value)) {
            throw new ValidateException("名称不能为空");
        }
        if (!flowConfig.checkChar(value)) {
            throw new ValidateException("名称中不能含有”字符");
        }
        if (!flowConfig.checkChar(title)) {
            throw new ValidateException("提示信息中不能含有“字符");
        }

        flowConfig.modify(name, value, title, isDisplay);

        return new Result<>();
    }

    @ApiOperation(value = "编辑用户等级页面", notes = "编辑用户等级页面", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/editUserLevelPage")
    @ResponseBody
    public Result<Object> editUserLevelPage() throws ValidateException {
        UserLevelDb uld = new UserLevelDb();
        Vector v = uld.getAllLevel();
        JSONArray ary = new JSONArray();
        for (Object o : v) {
            uld = (UserLevelDb) o;
            JSONObject json = new JSONObject();
            json.put("level", uld.getLevel());
            json.put("desc", uld.getDesc());
            json.put("picPath", uld.getLevelPicPath());
            ary.add(json);
        }
        return new Result<>(ary);
    }

    @ApiOperation(value = "创建用户等级", notes = "创建用户等级", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/createUserLevel", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> createUserLevel() {
        UserLevelMgr userLevelMgr = new UserLevelMgr();
        boolean re;
        try {
            re = userLevelMgr.create(request);
        } catch (ErrMsgException e) {
            return new Result<>(false, e.getMessage());
        }

        return new Result<>(re);
    }

    @ApiOperation(value = "保存用户等级", notes = "保存用户等级", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/updateUserLevel", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> updateUserLevel() {
        UserLevelMgr userLevelMgr = new UserLevelMgr();
        boolean re;
        try {
            re = userLevelMgr.modify(request);
        } catch (ErrMsgException e) {
            return new Result<>(false, e.getMessage());
        }
        return new Result<>(re);
    }

    @ApiOperation(value = "删除用户等级", notes = "删除用户等级", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/delUserLevel", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> delUserLevel() {
        UserLevelMgr userLevelMgr = new UserLevelMgr();
        boolean re;
        try {
            re = userLevelMgr.del(request);
        } catch (ErrMsgException e) {
            return new Result<>(false, e.getMessage());
        }
        return new Result<>(re);
    }

    @ApiOperation(value = "编辑安全配置页面", notes = "编辑安全配置页面", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/editSecurityPage")
    @ResponseBody
    public Result<Object> editSecurityPage() {
        JSONArray jsonAry = new JSONArray();
        com.redmoon.oa.security.Config myconfig = com.redmoon.oa.security.Config.getInstance();
        Element root = myconfig.getDoc().getRootElement();
        for (Object o : root.getChildren()) {
            Element e = (Element) o;
            String name = e.getName();

            String isDisplay = StrUtil.getNullStr(e.getAttributeValue("isDisplay"));
            if ("false".equals(isDisplay)) {
                continue;
            }

            String value = e.getValue();
            String desc = e.getAttributeValue("desc");
            List list = e.getChildren();
            if (list.size() > 0) {
                for (Object element : list) {
                    Element eChild = (Element) element;
                    String childName = eChild.getName();
                    childName = name + "." + childName;
                    isDisplay = StrUtil.getNullStr(eChild.getAttributeValue("isDisplay"));
                    if ("false".equals(isDisplay)) {
                        continue;
                    }
                    value = eChild.getValue();
                    String type = "";
                    if ("true".equals(value) || "false".equals(value)) {
                        type = "boolean";
                    }
                    desc = eChild.getAttributeValue("desc");

                    JSONObject json = new JSONObject();
                    json.put("name", childName);
                    json.put("value", value);
                    json.put("desc", desc);
                    json.put("isDisplay", isDisplay);

                    JSONArray optAry = new JSONArray();
                    String opts = eChild.getAttributeValue("options");
                    String[] ary = StrUtil.split(opts, ",");
                    if (ary != null) {
                        for (String item : ary) {
                            String[] aryOpts = StrUtil.split(item, "\\|");
                            if (aryOpts != null && aryOpts.length == 2) {
                                JSONObject jsonObject = new JSONObject();
                                jsonObject.put("value", aryOpts[0]);
                                jsonObject.put("name", aryOpts[1]);
                                optAry.add(jsonObject);
                            }
                        }
                    }
                    json.put("options", optAry);
                    if (optAry.size() > 0) {
                        type = "select";
                    }
                    json.put("type", type);
                    jsonAry.add(json);
                }
            } else {
                JSONObject json = new JSONObject();
                json.put("name", name);
                json.put("value", value);
                String type = "";
                if ("true".equals(value) || "false".equals(value)) {
                    type = "boolean";
                }
                json.put("desc", desc);
                json.put("isDisplay", isDisplay);

                JSONArray optAry = null;
                String opts = e.getAttributeValue("options");
                String[] ary = StrUtil.split(opts, ",");
                if (ary != null) {
                    optAry = new JSONArray();
                    for (String item : ary) {
                        String[] aryOpts = StrUtil.split(item, "\\|");
                        if (aryOpts != null && aryOpts.length == 2) {
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put("value", aryOpts[0]);
                            jsonObject.put("name", aryOpts[1]);
                            optAry.add(jsonObject);
                        }
                    }
                }
                json.put("options", optAry);
                if (optAry!=null && optAry.size() > 0) {
                    type = "select";
                }
                json.put("type", type);
                jsonAry.add(json);
            }
        }

        return new Result<>(jsonAry);
    }

    @ApiOperation(value = "保存安全配置", notes = "保存安全配置", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/updateSecurity", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> updateSecurity(String name, String value) {
        com.redmoon.oa.security.Config myconfig = com.redmoon.oa.security.Config.getInstance();
        myconfig.setProperty(name, value);
        myconfig.refresh();
        return new Result<>();
    }

    @ApiOperation(value = "置是否启用短信", notes = "置是否启用短信", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "isUsed", value = "是否启用", required = true, dataType = "Boolean"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/setSms", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> setSms(@RequestParam Boolean isUsed) {
        com.redmoon.oa.sms.Config cfg = new com.redmoon.oa.sms.Config();
        cfg.setIsUsed(isUsed);
        com.redmoon.oa.sms.SMSFactory.init();
        com.redmoon.oa.sms.SMSFactory.getMsgUtil();
        return new Result<>();
    }

    @ApiOperation(value = "编辑开发者页面", notes = "编辑开发者页面", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/editDeveloperPage")
    @ResponseBody
    public Result<Object> editDeveloperPage() {
        JSONObject json = new JSONObject();
        CloudConfig cfg = CloudConfig.getInstance();
        json.put("developers", cfg.getDevelopers());
        return new Result<>(json);
    }

    @ApiOperation(value = "保存开发者", notes = "保存开发者", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "userSecret", value = "用户secret", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/updateDeveloper", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> updateDeveloper(@RequestParam(value = "userName") String userName, @RequestParam(value = "userSecret") String userSecret) {
        CloudConfig cfg = CloudConfig.getInstance();
        return new Result<>(cfg.modifyDeveloper(userName, userSecret));
    }

    @ApiOperation(value = "删除开发者", notes = "删除开发者", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/delDeveloper", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> delDeveloper(@RequestParam(value = "userName") String userName) {
        CloudConfig cfg = CloudConfig.getInstance();
        return new Result<>(cfg.delDeveloper(userName));
    }

    @ApiOperation(value = "创建开发者", notes = "创建开发者", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "userSecret", value = "userSecret", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/createDeveloper", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> createDeveloper(@RequestParam(value = "userName") String userName, @RequestParam(value = "userSecret") String userSecret) throws ValidateException {
        CloudConfig cfg = CloudConfig.getInstance();
        return new Result<>(cfg.addDeveloper(userName, userSecret));
    }

    @ApiOperation(value = "创建配置项", notes = "创建配置项", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "参数名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "value", value = "参数值", required = true, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "String"),
            @ApiImplicitParam(name = "options", value = "选项", required = true, dataType = "String"),
            @ApiImplicitParam(name = "kind", value = "类别", required = true, dataType = "String"),
            @ApiImplicitParam(name = "desc", value = "描述", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/createConfigItem", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> createConfigItem(@RequestParam(value = "name") String name, @RequestParam(value = "value") String value,
                                           @RequestParam(value = "type") String type, @RequestParam(value = "options") String options,
                                           @RequestParam(value = "kind") String kind, @RequestParam(value = "desc") String desc) {
        XMLConfig cfg = new XMLConfig("config.xml", false, "utf-8");
        // 向root节点添加新的子节点
        Element root = cfg.getRootElement();
        Element oaEl = root.getChild("oa");
        Element newElem = new Element(name);
        newElem.setAttribute("type", type);
        if ("select".equals(type)) {
            if (!StrUtil.isEmpty(options)) {
                JSONArray ary = JSONArray.parseArray(options);
                if (ary!=null && ary.size() > 0) {
                    StringBuilder sb = new StringBuilder();
                    for (Object o : ary ) {
                        JSONObject json = (JSONObject)o;
                        StrUtil.concat(sb, ",", json.getString("value") + "|" + json.getString("name"));
                    }
                    options = sb.toString();
                }
            }
        } else {
            options = "";
        }
        newElem.setAttribute("options", options);
        newElem.setAttribute("kind", kind);
        newElem.setAttribute("desc", desc);
        newElem.setText(value);
        oaEl.addContent(newElem);

        cfg.writemodify();
        Config.getInstance().init();
        return new Result<>();
    }

    @ApiOperation(value = "删除配置项", notes = "删除配置项", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/delElement", produces = {"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Result<Object> delElement(@RequestParam(value = "name") String name) {
        XMLConfig cfg = new XMLConfig("config.xml", false, "utf-8");
        Element root = cfg.getRootElement();
        Element oaEl = root.getChild("oa");
        oaEl.removeChild(name);
        cfg.writemodify();
        Global.getInstance().init();
        return new Result<>();
    }

    @ApiOperation(value = "取流程处理过程列表的表头设置", notes = "取流程处理过程列表的表头设置", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "isForManager", value = "是否为管理员而设置", required = true, dataType = "Boolean"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @ResponseBody
    @RequestMapping(value = "/getMyActionListCols", method = RequestMethod.POST, produces = {"text/html;", "application/json;charset=UTF-8;"})
    public Result<Object> getMyActionListCols(@RequestParam Boolean isForManager) {
        WorkflowConfig workflowConfig = WorkflowConfig.getInstance();
        String r = "";
        if (isForManager) {
            r = workflowConfig.getProperty("flowMyActionListColsForManager");
        } else {
            r = workflowConfig.getProperty("flowMyActionListColsForNormal");
        }
        if (StrUtil.isEmpty(r)) {
            return new Result<>(new JSONArray());
        } else {
            JSONArray ary = JSONArray.parseArray(r);
            return new Result<>(ary);
        }
    }

    @ApiOperation(value = "保存流程处理过程列表的表头设置", notes = "保存流程处理过程列表的表头设置", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ary", value = "参数", required = true, dataType = "JSONArray"),
            @ApiImplicitParam(name = "isForManager", value = "是否为管理员而设置", required = true, dataType = "Boolean"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PreAuthorize("hasAnyAuthority('admin')")
    @ResponseBody
    @RequestMapping(value = "/setMyActionListCols", method = RequestMethod.POST, produces = {"text/html;", "application/json;charset=UTF-8;"})
    public Result<Object> setMyActionListCols(@RequestBody com.alibaba.fastjson.JSONObject json) {
        boolean isForManager = json.getBoolean("isForManager");
        JSONArray ary = json.getJSONArray("ary");
        WorkflowConfig workflowConfig = WorkflowConfig.getInstance();
        if (isForManager) {
            workflowConfig.setProperty("flowMyActionListColsForManager", ary.toString());
        } else {
            workflowConfig.setProperty("flowMyActionListColsForNormal", ary.toString());
        }
        return new Result<>();
    }
}
